/*
* Copyright (C) Microsoft. All rights reserved.  
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not 
* use this file except in compliance with the License.  You may obtain a copy 
* of the License at http://www.apache.org/licenses/LICENSE-2.0  
* 
* THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
* WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
* MERCHANTABLITY OR NON-INFRINGEMENT. 
*
* See the Apache License, Version 2.0 for specific language governing 
* permissions and limitations under the License.
*
*/
#include "pch.h"
#include <baja/db/db_result.h>

using namespace baja::storage;

result_row::result_row()
{
    _cells = std::make_shared<std::vector<std::shared_ptr<icell>>>();
}

std::shared_ptr<result_row> result_row::create()
{
    return std::make_shared<result_row>();
}

void result_row::addCell(std::shared_ptr<icell> cell)
{
    _cells->push_back(cell);
}

std::shared_ptr<std::vector<std::shared_ptr<icell>>> result_row::getCells()
{
    return _cells;
}

std::shared_ptr<iresult_row> baja::storage::createRow()
{
    return result_row::create();
}

result::result()
{
    _columns = std::make_shared<std::vector<std::shared_ptr<icolumn>>>();
    _rows = std::make_shared<std::vector<std::shared_ptr<iresult_row>>>();
}

std::shared_ptr<result> result::create()
{
    return std::make_shared<result>();
}

void result::addColumn(std::shared_ptr<icolumn> column)
{
    _columns->push_back(column);    
}

std::shared_ptr<std::vector<std::shared_ptr<icolumn>>> result::getColumns()
{
    return _columns;
}

void result::addRow(std::shared_ptr<iresult_row> row)
{
    _rows->push_back(row);
}

std::shared_ptr<std::vector<std::shared_ptr<iresult_row>>> result::getRows()
{
    return _rows;
}

void result::dump()
{
    std::vector<std::shared_ptr<iresult_row>>::iterator rowIt;
    for (rowIt = _rows->begin() ; rowIt < _rows->end() ; ++rowIt)
    {
        std::shared_ptr<iresult_row> row = *rowIt;
        std::shared_ptr<std::vector<std::shared_ptr<icell>>> cells = row->getCells();
        std::vector<std::shared_ptr<icell>>::iterator cellIt;
        for (cellIt = cells->begin() ; cellIt < cells->end() ; ++cellIt)
        {
            std::shared_ptr<icell> cell = *cellIt;
            cell->dump();
        }
    }
}

std::shared_ptr<iresult> baja::storage::createResult()
{
    return result::create();
}